import request from '@/utils/request'

// 查询支付退款列表
export function listPayRefund(query) {
  return request({
    url: '/pay/refund/list',
    method: 'get',
    params: query
  })
}

// 查询支付退款详细
export function getPayRefund(id) {
  return request({
    url: '/pay/refund/' + id,
    method: 'get'
  })
}

// 新增支付退款
export function addPayRefund(data) {
  return request({
    url: '/pay/refund',
    method: 'post',
    data: data
  })
}

// 修改支付退款
export function updatePayRefund(data) {
  return request({
    url: '/pay/refund',
    method: 'put',
    data: data
  })
}

// 删除支付退款
export function delPayRefund(id) {
  return request({
    url: '/pay/refund/' + id,
    method: 'delete'
  })
}

// 根据订单号查询退款记录
export function getPayRefundByOrderNo(orderNo) {
  return request({
    url: '/pay/refund/order/' + orderNo,
    method: 'get'
  })
}

// 根据退款流水号查询退款记录
export function getPayRefundByRefundNo(refundNo) {
  return request({
    url: '/pay/refund/refundno/' + refundNo,
    method: 'get'
  })
}

// 根据第三方退款流水号查询退款记录
export function getPayRefundByThirdRefundNo(thirdRefundNo) {
  return request({
    url: '/pay/refund/third/' + thirdRefundNo,
    method: 'get'
  })
}

// 根据用户ID查询退款记录
export function getPayRefundByUserId(userId) {
  return request({
    url: '/pay/refund/user/' + userId,
    method: 'get'
  })
}

// 根据退款状态查询退款记录
export function getPayRefundByRefundStatus(refundStatus) {
  return request({
    url: '/pay/refund/status/' + refundStatus,
    method: 'get'
  })
}

// 统计用户退款金额
export function getTotalRefundAmountByUserId(userId) {
  return request({
    url: '/pay/refund/stats/amount/' + userId,
    method: 'get'
  })
}

// 检查订单是否可以退款
export function canRefund(orderNo) {
  return request({
    url: '/pay/refund/check/' + orderNo,
    method: 'get'
  })
}

// 获取订单已退款金额
export function getRefundedAmount(orderNo) {
  return request({
    url: '/pay/refund/refunded/' + orderNo,
    method: 'get'
  })
}

// 手动创建退款
export function createRefund(data) {
  return request({
    url: '/pay/refund/create',
    method: 'post',
    data: data
  })
}

// 审批退款
export function approveRefund(data) {
  return request({
    url: '/pay/refund/approve',
    method: 'post',
    data: data
  })
} 